#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "SharedMemory.h"

/*  Process 2 tries to unlock (suppose to print 1 =>fail) attach to same mem as process1    *
 *  Then lock and prints the content of the sharem memory, unlock and deattach             */
int main()
{
    SM*     sm      = SMAttach("smtest")   ;
    void*   memory  = SMGet(sm)             ;

    printf("Process2: Unlock operation %d\n",SMUnlock(sm));

    printf("Process2: Lock operation %d\n",SMLock(sm));
    printf("Process2: Printing from the shared memory\n");
    printf("%s\n", (char*)memory);

    printf("Process2: Unlock operation: %d\n",SMUnlock(sm));
    SMDetach(sm);

    return 0;
}
